package IO流;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Locale;

public class 行数 {
    public static long rows=0;
    public static long filecount=0;
    public static void main(String[] args) throws FileNotFoundException {
        count(new File("F:\\IDEA\\maven-String"));
        System.out.println("写了"+rows);
        System.out.println("文件"+filecount);
    }
    public static void count(File file) throws FileNotFoundException {

            for(File t:file.listFiles()){
                if(t.isDirectory()){
                    count(t);
                }else if(t.getName().toLowerCase().endsWith(".java")){
                    rows+=rows(t);
                    ++filecount;

            }
        }
    }
    public static long rows (File file) throws FileNotFoundException {
        long rows=0;
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            rows = br.lines().count();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return rows;

    }
}
